<?php
/**
 * 静的URL・パンくず生成クラス
 * @package Apm
 * @author hiasa-ryousuke@systemsoft.co.jp
 * @since 2010/11/5
 */
class Apm_Bukkenbreadcrumb{

	const SRH_BREAD_KBN = "SRH_";

	private static $_breadcrumb = null;
	private static $_pankuzu    = array();

	private static $_researchData = null;

	private static $_baseurl = "";

	public static function generateBukkenbreadcrumb($params, $researchData, $breadcrumb=null)
	{
		if (is_null($breadcrumb)) {
			Apm_Bukkenbreadcrumb::$_breadcrumb = new Apm_Breadcrumb();
		} else {
			Apm_Bukkenbreadcrumb::$_breadcrumb = $breadcrumb;
		}
		Apm_Bukkenbreadcrumb::$_breadcrumb->reset();
		
		$configObject = Zend_Registry::get('config');
		$config = $configObject->apm->toArray();
		Apm_Bukkenbreadcrumb::$_baseurl = $config["baseurl"];
		Apm_Bukkenbreadcrumb::$_breadcrumb->add(Apm_Config_Search::BREADCRUMB_TOP, Apm_Bukkenbreadcrumb::$_baseurl);
		
		Apm_Bukkenbreadcrumb::$_researchData = $researchData;
		
		switch ($params['Pattern'])
		{
			case 'type':
				Apm_Bukkenbreadcrumb::generateBreadcrumbType($params);
			break;
			case 'chiiki':
				Apm_Bukkenbreadcrumb::generateBreadcrumbChiiki($params);
			break;
			case 'station':
				Apm_Bukkenbreadcrumb::generateBreadcrumbStation($params);
			break;
			case 'kodawari':
				Apm_Bukkenbreadcrumb::generateBreadcrumbKodawari($params);
			break;
			case 'x2':
				Apm_Bukkenbreadcrumb::generateBreadcrumbX2($params);
			break;
			case 'x2s':
				Apm_Bukkenbreadcrumb::generateBreadcrumbX2s($params);
			break;
			case 'x3':
				Apm_Bukkenbreadcrumb::generateBreadcrumbX3($params);
			break;
			case 'x4':
				Apm_Bukkenbreadcrumb::generateBreadcrumbX4($params);
			break;
			case 'x4s':
				Apm_Bukkenbreadcrumb::generateBreadcrumbX4s($params);
			break;
			case 'x5':
				Apm_Bukkenbreadcrumb::generateBreadcrumbX5($params);
			break;
			case 'x5s':
				Apm_Bukkenbreadcrumb::generateBreadcrumbX5s($params);
			break;
			//case 'detail':
				//Apm_Bukkenbreadcrumb::generateBreadcrumbDetail($params);
			//break;
		}
		// 市区町村Moreの場合、エリアで絞り込むを追加
		if (!empty($params['CityMore'])) {
			$title = "エリアで絞り込む";
			$url   = "";
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'CITYMORE';
			Apm_Bukkenbreadcrumb::$_breadcrumb->addTailArr($title, $url, $key);
			Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr("");
		}
		
		Apm_Bukkenbreadcrumb::setBreadcrumbSettion();
	}

	//////////////////////////////////////////////////
	// パターン別処理
	//////////////////////////////////////////////////
	private static function generateBreadcrumbType($params)
	{
		//Apm_Bukkenbreadcrumb::setBreadcrumbTypeSearch();
		Apm_Bukkenbreadcrumb::setBreadcrumbType($params);
		// 2014.06.23 パンくずリスト改善
		$bread = array_pop(Apm_Bukkenbreadcrumb::$_pankuzu);
		$title = $bread['title'].'を探す';
		$url   = $bread['url'];
		$key   = $bread['key'];
		Apm_Bukkenbreadcrumb::$_breadcrumb->addTailArr($title, $url, $key);
		return;
	}

	private static function generateBreadcrumbChiiki($params)
	{
		//Apm_Bukkenbreadcrumb::setBreadcrumbJyusyoSearch();
		Apm_Bukkenbreadcrumb::setBreadcrumbAreacat($params, 'chiiki');
		//Apm_Bukkenbreadcrumb::setBreadcrumbChintaiAdd();
		switch ($params['Category']) {
			case '1.5':
				$tail = 'の賃貸を探す';
				Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr($tail);
				break;
			case '2':
				$title = "地域から賃貸を探す";
				$url   = "";
				$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'CHIIKI';
				Apm_Bukkenbreadcrumb::$_breadcrumb->addTailArr($title, $url, $key);
				break;
			case '2.5':
			case '3':
			case '4':
				$tail = 'から賃貸を探す';
				Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr($tail);
				break;
		}
		return;
	}

	private static function generateBreadcrumbStation($params)
	{
		if ($params['Category'] == '0') {
			Apm_Bukkenbreadcrumb::setBreadcrumbEnsenekiSearch();
		} else {
			Apm_Bukkenbreadcrumb::setBreadcrumbStationcat($params, 'station');
			//Apm_Bukkenbreadcrumb::setBreadcrumbChintaiAdd();
			switch ($params['Category']) {
				case '2':
					$title = "沿線から賃貸を探す";
					$url   = "";
					$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'CHIIKI';
					Apm_Bukkenbreadcrumb::$_breadcrumb->addTailArr($title, $url, $key);
					break;
				case '2.5':
					$tail = 'の駅から賃貸を探す';
					Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr($tail);
					break;
				case '3':
					$tail = 'から賃貸を探す';
					Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr($tail);
					break;
			}
		}
		return;
	}

	private static function generateBreadcrumbKodawari($params)
	{
		if ($params['Category'] == '0') {
			Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearch($params);
		} else {
			Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearchTop($params);
			Apm_Bukkenbreadcrumb::setBreadcrumbKodawari($params);
			//Apm_Bukkenbreadcrumb::setBreadcrumbChintaiAdd();
			$tail = 'から賃貸を探す';
			Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr($tail);
		}
		return;
	}

	private static function generateBreadcrumbX2($params)
	{
		// 2014.06.23 パンくずリスト改善
		Apm_Bukkenbreadcrumb::setBreadcrumbAreacat($params, 'chiiki');
		Apm_Bukkenbreadcrumb::setBreadcrumbTypeIdAdd3($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbType($params);
		////Apm_Bukkenbreadcrumb::setBreadcrumbJyusyoSearch();
		//Apm_Bukkenbreadcrumb::setBreadcrumbAreacat($params, 'x2');
		//Apm_Bukkenbreadcrumb::setBreadcrumbTypeIdAdd2($params);
		return;
	}

	private static function generateBreadcrumbX2s($params)
	{
		// 2014.06.23 パンくずリスト改善
		Apm_Bukkenbreadcrumb::setBreadcrumbStationcat($params, 'station');
		Apm_Bukkenbreadcrumb::setBreadcrumbTypeIdAdd3($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbType($params);
		////Apm_Bukkenbreadcrumb::setBreadcrumbEnsenekiSearch();
		//Apm_Bukkenbreadcrumb::setBreadcrumbStationcat($params, 'x2');	// sはつけない
		//Apm_Bukkenbreadcrumb::setBreadcrumbTypeIdAdd2($params);
		return;
	}

	private static function generateBreadcrumbX3($params)
	{
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearchTop($params);
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawari($params);
		// tail対応
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariTypeIdAdd2($params);
		$tail = Apm_Bukkenbreadcrumb::$_breadcrumb->getTailStr();
		Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr("");
		$title = mb_substr($tail, 2);
		$url   = "";
		$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . Apm_Config_Search::SRHKBN_JYUKYOKEITAI;
		Apm_Bukkenbreadcrumb::$_breadcrumb->addTailArr($title, $url, $key);
		//Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearch($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbTypeKodawari($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbChintaiAdd();
		return;
	}

	private static function generateBreadcrumbX4($params)
	{
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearchTop($params);
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawari($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearch($params);
		Apm_Bukkenbreadcrumb::setBreadcrumbAreacat($params, 'x4');
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariIdAdd2($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbChintaiAdd();
		return;
	}

	private static function generateBreadcrumbX4s($params)
	{
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearchTop($params);
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawari($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbEnsenekiSearch();
		Apm_Bukkenbreadcrumb::setBreadcrumbStationcat($params, 'x4');	// sはつけない
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariIdAdd2($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbChintaiAdd();
		return;
	}

	private static function generateBreadcrumbX5($params)
	{
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearchTop($params);
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawari($params);
		Apm_Bukkenbreadcrumb::setBreadcrumbTypeForKodawari($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbJyusyoSearch();
		Apm_Bukkenbreadcrumb::setBreadcrumbAreacat($params, 'x5');
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariTypeIdAdd2($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbKodawariIdAdd($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbTypeIdAdd($params);
		return;
	}

	private static function generateBreadcrumbX5s($params)
	{
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariSearchTop($params);
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawari($params);
		Apm_Bukkenbreadcrumb::setBreadcrumbTypeForKodawari($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbEnsenekiSearch();
		Apm_Bukkenbreadcrumb::setBreadcrumbStationcat($params, 'x5');	// sはつけない
		Apm_Bukkenbreadcrumb::setBreadcrumbKodawariTypeIdAdd2($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbKodawariIdAdd($params);
		//Apm_Bukkenbreadcrumb::setBreadcrumbTypeIdAdd($params);
		return;
	}

	public static function generateBreadcrumbDetail($params)
	{
		$configObject = Zend_Registry::get('config');
		$config = $configObject->apm->toArray();
		Apm_Bukkenbreadcrumb::setBreadcrumb(Apm_Config_Search::BREADCRUMB_TOP, $config["baseurl"], $config["baseurl"]);
		//Apm_Bukkenbreadcrumb::setBreadcrumbJyusyoSearch();
		Apm_Bukkenbreadcrumb::setBreadcrumbAreacat($params, 'chiiki');
		Apm_Bukkenbreadcrumb::setBreadcrumbDetail($params);
		return Apm_Bukkenbreadcrumb::getBreadcrumbString();
	}

	public static function generateBreadcrumbShop($params, $breadcrumb=null)
	{
		if (is_null($breadcrumb)) {
			Apm_Bukkenbreadcrumb::$_breadcrumb = new Apm_Breadcrumb();
		} else {
			Apm_Bukkenbreadcrumb::$_breadcrumb = $breadcrumb;
		}
		Apm_Bukkenbreadcrumb::$_breadcrumb->reset();
		
		$configObject = Zend_Registry::get('config');
		$config = $configObject->apm->toArray();
		Apm_Bukkenbreadcrumb::$_baseurl = $config["baseurl"];
		Apm_Bukkenbreadcrumb::$_breadcrumb->add(Apm_Config_Search::BREADCRUMB_TOP, Apm_Bukkenbreadcrumb::$_baseurl);
		
		//Apm_Bukkenbreadcrumb::$_researchData = $researchData;
		
		if ($params['SrhType'] == Apm_Config_Shop::SEARCH_TYPE_RAIL) {
			Apm_Bukkenbreadcrumb::setBreadcrumbStationcat($params, 'station');
		} else {
			Apm_Bukkenbreadcrumb::setBreadcrumbAreacat($params, 'chiiki');
		}
		
		if (empty($params['ShopCd'])) {
			$title = "店舗を探す";
			$url   = "";
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'SHOP';
			Apm_Bukkenbreadcrumb::$_breadcrumb->addTailArr($title, $url, $key);
		} else {
			//$title = "店舗を探す";
			//$url   = "";
			//$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'SHOPDETAIL';
		}
		
		Apm_Bukkenbreadcrumb::setBreadcrumbSettion();
	}

	// パンくず配列をセッションへ登録
	private static function setBreadcrumbSettion()
	{
		foreach (Apm_Bukkenbreadcrumb::$_pankuzu as $key => $val) {
			Apm_Bukkenbreadcrumb::$_breadcrumb->add($val['title'], $val['url'], $val['key']);
		}
	}

	// パンくず配列からパンくずString生成（物件詳細用）
	private static function getBreadcrumbString()
	{
		//$breadcrumb_str = "";
		$breadcrumb_arr = Apm_Bukkenbreadcrumb::$_pankuzu;
		
		$tmp = array();
		$count = count($breadcrumb_arr);
		$end_index = $count - 1;
		
		for ($i=0; $i<$count-1; $i++) {
			$tmp[] = sprintf('<a href="%s">%s</a>', $breadcrumb_arr[$i]['url'], $breadcrumb_arr[$i]['title']);
		}
		$tmp[] = '<li><strong>'.$breadcrumb_arr[$end_index]['title'].'</strong></li>';
		return implode('', $tmp);
/*
		// 最後の要素のリンクを外す
		$bread = array_pop($breadcrumb_arr);
		$bread['url'] = "";
		$breadcrumb_arr[] = $bread;
		// String生成
		foreach ($breadcrumb_arr as $key => $val) {
			$str = $val['title'];
			if (!empty($val['url'])) {
				$str = '<a href="'.$val['url'].'">'.$str.'</a>';
			}
			$breadcrumb_str .= $str;
		}
*/
		return $breadcrumb_str;
	}

	//////////////////////////////////////////////////
	// 検索導線パンくず生成
	//////////////////////////////////////////////////
	private static function setBreadcrumbAreaSearch()
	{
		$title = "エリアから賃貸を探す";
		$url   = Apm_Bukkenbreadcrumb::$_baseurl."search/jyusyosearch/";
		$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . Apm_Config_Search::SRHKBN_AREA;
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbJyusyoSearch()
	{
		$title = "住所から賃貸を探す";
		$url   = Apm_Bukkenbreadcrumb::$_baseurl."search/jyusyosearch/";
		$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . Apm_Config_Search::SRHKBN_JYUSYO;
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbEnsenekiSearch()
	{
		$title = "沿線・駅から賃貸を探す";
		$url   = Apm_Bukkenbreadcrumb::$_baseurl."station/";
		$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . Apm_Config_Search::SRHKBN_ENSENEKI;
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbKodawariSearch($params)
	{
		// **災害支援住宅対応**
		if ($params['KodawariId'] == "38" || $params['KodawariId'] == "39") return;
		
		$title = "こだわりから賃貸を探す";
		$url   = Apm_Bukkenbreadcrumb::$_baseurl."kodawari/";
		$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . Apm_Config_Search::SRHKBN_KODAWARI;
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}
	private static function setBreadcrumbKodawariSearchTop($params)
	{
		// **災害支援住宅対応**
		if ($params['KodawariId'] == "38" || $params['KodawariId'] == "39") return;
		
		$title = "こだわり";
		$url   = Apm_Bukkenbreadcrumb::$_baseurl."kodawari/";
		$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . Apm_Config_Search::SRHKBN_KODAWARI;
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbTypeSearch()
	{
		$title = "住居形態から賃貸を探す";
		$url   = "_blank";
		$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . Apm_Config_Search::SRHKBN_JYUKYOKEITAI;
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	//////////////////////////////////////////////////
	// パラメータからパンくず生成
	//////////////////////////////////////////////////
	private static function setBreadcrumb($title, $url, $key)
	{
		if ($title != "" && $key != "") {
			$bread = array('title'=>$title, 'url'=>$url, 'key'=>$key);
			Apm_Bukkenbreadcrumb::$_pankuzu[] = $bread;
			//echo "<BR>【パンくず追加】title=".$title.":url=".$url.":key=".$key."<BR>";
		}
		else {
			//echo "<BR>【パンくず追加エラー】title=".$title.":url=".$url.":key=".$key."<BR>";
		}
	}

	private static function setBreadcrumbType($params)
	{
		// 建物種別IDを取得
		$typeId  = $params['TatemonoTypeCd'];
		$typeStr = array_search($typeId, Apm_Config_Search::$TATEMONO_SYUBETU_ID_LIST);
		//$typeId = Apm_Config_Search::$TATEMONO_SYUBETU_ID_LIST[$params['TatemonoTypeCd']];
		
		$title  = str_replace('賃貸', '', Apm_Config_Search::$KENSAKU_TATEMONO_SYUBETU['syubetu'.$typeId]);
		$url    = Apm_Bukkenurl::generateUrlByParameters(array('TatemonoType'=>$typeStr), 'type');
		$key    = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'TYPE';
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbKodawari($params)
	{
		$title  = Apm_Config_Search::$KODAWARI_ID_STR_LIST[$params['KodawariId']];
		$url    = Apm_Bukkenurl::generateUrlByParameters($params, 'kodawari');
		$key    = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'KODAWARI';
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbTypeKodawari($params)
	{
		// マンション重複対応
		$TatemonoType = Apm_Config_Search::$KENSAKU_TATEMONO_SYUBETU['syubetu'.$params['TatemonoTypeCd']];
		$Kodawari     = str_replace('マンション', '', Apm_Config_Search::$KODAWARI_ID_STR_LIST[$params['KodawariId']]);
		//if (strpos($Kodawari,'マンション') !== false && strpos($TatemonoType,'マンション') !== false) {
		//	$TatemonoType = '賃貸';
		//}
		
		$title  = $Kodawari." ".$TatemonoType;
		$url    = Apm_Bukkenurl::generateUrlByParameters($params, 'x3');
		$key    = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'TYPE_KODAWARI';
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbTypeForKodawari($params)
	{
		// マンション重複対応
		$typeId  = $params['TatemonoTypeCd'];
		$typeStr = array_search($typeId, Apm_Config_Search::$TATEMONO_SYUBETU_ID_LIST);
		
		$title  = str_replace('賃貸', '', Apm_Config_Search::$KENSAKU_TATEMONO_SYUBETU['syubetu'.$typeId]);
		$url    = Apm_Bukkenurl::generateUrlByParameters($params, 'x3');
		$key    = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'TYPE_KODAWARI';
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbAreacat($params, $pattern)
	{
		// クロスカテゴリID生成
		//$id_str  = $params['TatemonoTypeCd'];
		//if (!empty($id_str) && !empty($params['KodawariId'])) $id_str .= "-";
		//$id_str .= $params['KodawariId'];
		
		// 住所データ取得
		if (empty(Apm_Bukkenbreadcrumb::$_researchData)) {
			$_model_re_search   = new Search_Model_ResearchPanel();
			$ResearchData = $_model_re_search->convertResarchPanel(Apm_Config_Search::SRHKBN_JYUSYO, $params);
		} else {
			$ResearchData = &Apm_Bukkenbreadcrumb::$_researchData;
		}
		
		// エリア取得
		$areaCd = "";
		$title  = "";
		if (!empty($ResearchData['AreaCd']) && !empty($params['AreaCd'])) {
			$areaCd = &$ResearchData['AreaCd'][$params['AreaCd']]['AREA_ROMAN'];
			$title  =  $ResearchData['AreaCd'][$params['AreaCd']]['AREA_NAME'];
		} else {
			$_model_area_search = new Search_Model_Selareasearch();
			$AreaData = array();
			if (!empty($params['AreaCd'])) {
				$AreaData = $_model_area_search->getRomanArea($params['AreaCd']);
			}
			else if (!empty($params['PrefCd'])) {
				$AreaData = $_model_area_search->getSimpleArea($params['PrefCd'][0]);
			}
			if (!empty($AreaData)) {
				$areaCd = &$AreaData['M01_AREA_ROMAN_NAME'];
				$title  =  $AreaData['M01_AREA_NAME'];
			}
		}
		if (!empty($areaCd)) {
			$params['AreaName'] = $areaCd;
			if ($areaCd != 'hokkaido') {
				$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '1');
				$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'AREA';
				Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
			}
		} else {
			// エリアCD（ローマ字表記）が取得できなければ、以下スルー
			return;
		}
		
		// 都道府県取得
		$prefCd = "";
		$title  = "";
		if (!empty($ResearchData['PrefCd']) && !empty($params['PrefCd'])) {
			$prefCd = Apm_Config_Search::$TODOUFUKEN_NAME_CODE_LIST[$params['PrefCd'][0]];
			$title  = $ResearchData['PrefCd'][$params['PrefCd'][0]]['PREF_NAME'];
		}
		if (!empty($prefCd)) {
			$params['PrefName'] = $prefCd;
			if ($pattern == 'chiiki') {
				$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '1.5');
			} else {
				if (!empty($ResearchData['PrefCd'][$params['PrefCd'][0]]['PREF_ALIAS'])) $title = $ResearchData['PrefCd'][$params['PrefCd'][0]]['PREF_ALIAS'];
				$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '2');
			}
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'PREF';
			Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		} else {
			// 都道府県CD（ローマ字表記）が取得できなければ、以下スルー
			return;
		}
		
		// 政令指定都市取得
		$siteiName = "";
		if (!empty($ResearchData['SiteitosiCd'])) {
			if (empty($params['SiteitosiCd']) && !empty($params['CityCd'])) {
				// 政令指定都市CDが存在しない場合
				$_model_siku_search = new Search_Model_Selsikucyoson();
				$SiteiData  = $_model_siku_search->getSiteiFromCityCd($params['CityCd'][0]);
				$siteiName  = &$SiteiData['M44_SITEITOSI'];
				$siteiRoman = &$SiteiData['M44_SITEITOSI_ROMAN'];
			} else {
				$siteiName  = &$ResearchData['SiteitosiCd'][$params['SiteitosiCd'][0]]['SITEI_NAME'];
				$siteiRoman = &$ResearchData['SiteitosiCd'][$params['SiteitosiCd'][0]]['SITEI_ROMAN'];
			}
			$title = $siteiName;
			$params['SiteitosiName'] = $siteiRoman;
			$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '2.5');
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'SITEI';
			Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		}
		
		// 市区町村取得
		//$cityCd = "";
		$title  = "";
		if (!empty($ResearchData['CityCd']) && !empty($params['CityCd'])) {
		//	$cityCd = substr($params['CityCd'][0],2);
		//}
		//if (!empty($cityCd)) {
			$title  = $ResearchData['CityCd'][$params['CityCd'][0]]['CITY_NAME'];
			// 政令指定都市を追加している場合
			if (!empty($siteiName)) {
				// 政令指定都市名を市区町村名称からカット
				$title = mb_ereg_replace("(".$siteiName.")?", "", $title);
			}
			$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '3');
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'CITY';
			Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		} else {
			// 市区町村CDが取得できなければ、以下スルー
			return;
		}
		
		// 町名取得
		//$townCd = "";
		$title  = "";
		if (!empty($ResearchData['TownCd']) && !empty($params['TownCd'])) {
		//	$townCd = substr($params['TownCd'][0],5);
		//}
		//if (!empty($townCd)) {
			$title  = $ResearchData['TownCd'][$params['TownCd'][0]]['TOWN_NAME'];
			$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '4');
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'TOWN';
			Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		}
		
		return;
	}

	private static function setBreadcrumbStationcat($params, $pattern)
	{
		// クロスカテゴリID生成
		$id_str  = $params['TatemonoTypeCd'];
		if (!empty($id_str) && !empty($params['KodawariId'])) $id_str .= "-";
		$id_str .= $params['KodawariId'];
		
		if (empty(Apm_Bukkenbreadcrumb::$_researchData)) {
			$_model_re_search   = new Search_Model_ResearchPanel();
			$ResearchData = $_model_re_search->convertResarchPanel(Apm_Config_Search::SRHKBN_ENSENEKI, $params);
		} else {
			$ResearchData = &Apm_Bukkenbreadcrumb::$_researchData;
		}
		
		// エリア取得
		$areaCd = "";
		$title  = "";
		if (!empty($ResearchData['AreaCd']) && !empty($params['AreaCd'])) {
			$areaCd = &$ResearchData['AreaCd'][$params['AreaCd']]['AREA_ROMAN'];
			$title  =  $ResearchData['AreaCd'][$params['AreaCd']]['AREA_NAME'];
		} else {
			$_model_area_search = new Search_Model_Selareasearch();
			$AreaData = array();
			if (!empty($params['AreaCd'])) {
				$AreaData = $_model_area_search->getRomanArea($params['AreaCd']);
			}
			else if (!empty($params['PrefCd'])) {
				$AreaData = $_model_area_search->getSimpleArea($params['PrefCd'][0]);
			}
			if (!empty($AreaData)) {
				$areaCd = &$AreaData['M01_AREA_ROMAN_NAME'];
				$title  =  $AreaData['M01_AREA_NAME'];
			}
		}
		if (!empty($areaCd)) {
			$params['AreaName'] = $areaCd;
			if ($areaCd != 'hokkaido') {
				if ($pattern == 'station') {
					$url = Apm_Bukkenurl::generateUrlByParameters($params, 'chiiki', '1');
				} else {
					$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '1');
				}
				$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'AREA';
				Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
			}
		} else {
		}
		
		// 都道府県取得
		$prefCd = "";
		$title  = "";
		if (!empty($ResearchData['PrefCd']) && !empty($params['PrefCd'])) {
			$prefCd = Apm_Config_Search::$TODOUFUKEN_NAME_CODE_LIST[$params['PrefCd'][0]];
			$title  = $ResearchData['PrefCd'][$params['PrefCd'][0]]['PREF_NAME'];
		}
		if (!empty($prefCd)) {
			$params['PrefName'] = $prefCd;
			if ($pattern == 'station') {
				$url = Apm_Bukkenurl::generateUrlByParameters($params, 'chiiki', '1.5');
				//$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '1');
			} else {
				if (!empty($ResearchData['PrefCd'][$params['PrefCd'][0]]['PREF_ALIAS'])) $title = $ResearchData['PrefCd'][$params['PrefCd'][0]]['PREF_ALIAS'];
				$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '2');
			}
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'PREF';
			Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		} else {
		}
		
		// 駅取得
		if (!empty($ResearchData['StCd']) && !empty($params['StCd'])) {
			$title = $ResearchData['StCd'][$params['StCd'][0]]['ST_ALIAS'];
			if (empty($title)) $title = $ResearchData['StCd'][$params['StCd'][0]]['ST_NAME'];
			if ($pattern == 'station') {
				$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '3');
			} else {
				$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern.'s', '3');
			}
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'STCD';
			Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		}
		// 沿線取得
		else if (!empty($ResearchData['RailCd']) && !empty($params['RailCd']) && $pattern == 'station') {
			$title = $ResearchData['RailCd'][$params['RailCd'][0]]['RAIL_NAME'];
			if (!empty($prefCd)) {
				$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '2.5');
			} else {
				$url = Apm_Bukkenurl::generateUrlByParameters($params, $pattern, '2');
			}
			$key   = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'RAIL';
			Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		}
		
		return;
	}

	private static function setBreadcrumbDetail($params)
	{
		$title  = "物件詳細";
		//if (empty($params['COMMENT'])) {
		//	$title  = "物件詳細";
		//} else {
		//	$title  = $params['COMMENT'];
		//}
		$url = Apm_Bukkenurl::generateUrlByParameters($params, 'detail');
		$key    = 'RSTDTL';
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbTypeIdAdd($params)
	{
		// 建物種別名称を取得
		$TatemonoType = Apm_Config_Search::$KENSAKU_TATEMONO_SYUBETU['syubetu'.$params['TatemonoTypeCd']];
		
		// １つ前のパンくずを取得
		$bread = array_pop(Apm_Bukkenbreadcrumb::$_pankuzu);
		
		// 建物種別名称を追加
		$bread['title'] .= " " . $TatemonoType;
		
		// パンくずを修正
		Apm_Bukkenbreadcrumb::$_pankuzu[] = $bread;
		
		return;
	}
	private static function setBreadcrumbTypeIdAdd2($params)
	{
		// 建物種別名称を取得
		$TatemonoType = Apm_Config_Search::$KENSAKU_TATEMONO_SYUBETU['syubetu'.$params['TatemonoTypeCd']];
		$TatemonoType = str_replace('賃貸', '', $TatemonoType);
		
		$tail = "から".$TatemonoType."を探す";
		Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr($tail);
		
		return;
	}
	// 2014.06.23 パンくずリスト改善
	private static function setBreadcrumbTypeIdAdd3($params)
	{
		// 建物種別名称を取得
		$TatemonoType = Apm_Config_Search::$KENSAKU_TATEMONO_SYUBETU['syubetu'.$params['TatemonoTypeCd']];
		$TatemonoType = str_replace('賃貸', '', $TatemonoType);
		// １つ前のパンくずを取得
		$bread = array_pop(Apm_Bukkenbreadcrumb::$_pankuzu);
		array_push(Apm_Bukkenbreadcrumb::$_pankuzu, $bread);
		
		$title = $bread['title']."から".$TatemonoType."を探す";
		$url = '';
		$key    = Apm_Bukkenbreadcrumb::SRH_BREAD_KBN . 'TYPE';
		Apm_Bukkenbreadcrumb::setBreadcrumb($title, $url, $key);
		
		return;
	}

	private static function setBreadcrumbKodawariIdAdd($params)
	{
		// こだわり名称を取得
		$Kodawari = Apm_Config_Search::$KODAWARI_ID_STR_LIST[$params['KodawariId']];
		
		// マンション重複対応
		if (!empty($params['TatemonoTypeCd'])) {
			$Kodawari = str_replace('マンション', '', $Kodawari);
		}
		
		// １つ前のパンくずを取得
		$bread = array_pop(Apm_Bukkenbreadcrumb::$_pankuzu);
		
		// こだわり名称を追加
		$bread['title'] .= " " . $Kodawari;
		
		// パンくずを修正
		Apm_Bukkenbreadcrumb::$_pankuzu[] = $bread;
		
		return;
	}
	private static function setBreadcrumbKodawariIdAdd2($params)
	{
		// こだわり名称を取得
		$Kodawari = Apm_Config_Search::$KODAWARI_ID_STR_LIST[$params['KodawariId']];
		// マンション重複対応
		if (!empty($params['TatemonoTypeCd'])) {
			$Kodawari = str_replace('マンション', '', $Kodawari);
		}
		
		$tail = "から".$Kodawari."の賃貸を探す";
		Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr($tail);
		
		return;
	}

	private static function setBreadcrumbKodawariTypeIdAdd2($params)
	{
		// 建物種別名称を取得
		$TatemonoType = Apm_Config_Search::$KENSAKU_TATEMONO_SYUBETU['syubetu'.$params['TatemonoTypeCd']];
		$TatemonoType = str_replace('賃貸', '', $TatemonoType);
		// こだわり名称を取得
		$Kodawari = Apm_Config_Search::$KODAWARI_ID_STR_LIST[$params['KodawariId']];
		// マンション重複対応
		if (!empty($params['TatemonoTypeCd'])) {
			$Kodawari = str_replace('マンション', '', $Kodawari);
		}
		
		$tail = "から".$Kodawari."の".$TatemonoType."を探す";
		Apm_Bukkenbreadcrumb::$_breadcrumb->addTailStr($tail);
		
		return;
	}

	private static function setBreadcrumbChintaiAdd()
	{
		// １つ前のパンくずを取得
		$bread = array_pop(Apm_Bukkenbreadcrumb::$_pankuzu);
		
		// 名称を変更
		$bread['title'] .= " 賃貸";
		
		// パンくずを修正
		Apm_Bukkenbreadcrumb::$_pankuzu[] = $bread;
		
		return;
	}

}
?>
